package com.snopy.hash;

import com.snopy.utils.BinaryNumUtils;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;



/**
 * @author snopy
 * @version 1.0.0
 * @classname MyHashSet
 * @description
 * @email 77912204@qq.com
 * @date 2022/03/17 21:01
 */
@Slf4j
public class MyHashSet {

    public static final int MAX_CAPACITY = Integer.MAX_VALUE;
    Integer[] container;
    public MyHashSet() {
        this.container = new Integer[10];
    }

    public void add(int key) {

        container[key%1000000] = key;
    }

    public void remove(int key) {
        container[key%1000000] = null;
    }

    public boolean contains(int key) {
        return container[key%1000000] != null;
    }

    public static void main(String[] args) {

        HashMap<Integer,String> map = new HashMap<>(7);
        for (Integer i=0;i<=Integer.MAX_VALUE;i++){
            map.put(i,i.toString());
        }
        //int[] nums = new int[1310720];
        //int[] nums1 = new int[1310721];

        Integer nums = 1310711;

        Integer nums1 = 8;
//        int n = 5 - 1;
//        n |= n >>> 1;
//        n |= n >>> 2;
//        n |= n >>> 4;
//        n |= n >>> 8;
//        n |= n >>> 16;

        System.out.println(16*(0.75f));

        System.out.println(nums1/2);
        System.out.println(nums1>>1);
        int hashCode = nums.hashCode();
        int hashCode1 = nums1.hashCode();
        String binaryStr = BinaryNumUtils.toBinaryStr(hashCode);
        String binaryStr1 = BinaryNumUtils.toBinaryStr(hashCode1);
        log.info("hashcode:{},binary:{},hashcode:{},binary:{}",hashCode,binaryStr,hashCode1,binaryStr1);
        int yhi = hashCode>>>16;
        int yhi1 = hashCode1>>>16;
        String yhibinaryStr = BinaryNumUtils.toBinaryStr(yhi);
        String yhibinaryStr1 = BinaryNumUtils.toBinaryStr(yhi1);
        log.info("hashcode:{},binary:{},hashcode:{},binary:{}",yhi,yhibinaryStr,yhi1,yhibinaryStr1);
        int i1 = hashCode ^ yhi;
        int i11 = hashCode1 ^ yhi1;
        String i1binaryStr = BinaryNumUtils.toBinaryStr(i1);
        String i1binaryStr1 = BinaryNumUtils.toBinaryStr(i11);

        log.info("hashcode:{},binary:{},hashcode:{},binary:{}",i1,i1binaryStr,i11,i1binaryStr1);
//        00000000000100111111111111110111
//        00000000000000000000000000010011
//        00000000000100111111111111100100
          //16
        /*00010000

        00011100=16+8+4=28
        00011110=16+8+4+2=30
        00010111=16+4+2+1=23
        00011111=16+8+4+2+1=31
        00011101=16+8+4+1=29
        00011001=16+8+1=25
        00011011=16+8+2+1=27
        00010101=16+4+1=21
        00010001=16+1=17
        00010010=16+2=18
        00010100=16+4=20
        00011000=16+8=24
        00010011=16+1+2=19*/
    }
}
